# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
  include LoginEngine

  def fuzzytime question
    timeDiff = Time.now - question.created_at
    if timeDiff < 1.minute
      sec = timeDiff.round
      "#{sec} second#{'s' if sec>1} ago"
    elsif timeDiff < 1.hour
      min = (timeDiff/60).round
      "#{min} min#{'s' if min>1} ago"
    elsif timeDiff < 1.day
      hour = (timeDiff/3600).round
      "#{hour} hour#{'s' if hour>1} ago"
    elsif timeDiff < 7.day
      day = timeDiff/(86400).round
      "#{day} day#{'s' if day>1} ago"
    else # just print the exact date
      question.created_at.strftime("on %x")
    end
  end

end
